import React, { Component } from 'react'
import PropTypes from 'prop-types'

import styles from './index.module.styl'

class Page extends Component {
    render() {
        const {
            fetched,
            fetching,
            children,
        } = this.props

        return (
            <React.Fragment>
                {
                    fetched
                        ? children
                        : (
                            fetching ? <div className={styles.page}><img src="https://y.gtimg.cn/mediastyle/yqq/img/loading.gif" alt="" /></div> : null
                        )
                }
            </React.Fragment>
        )
    }
}

Page.propTypes = {
    fetched: PropTypes.bool,
    fetching: PropTypes.bool,
}


Page.defaultProps = {
    fetched: false,
    fetching: true,
}

export default Page